package com.sss.hloster07;

import java.util.*;

public class TestComparator {

	public static void main(String[] args) {
		test01();
	}

	private static void test01() {
		// 用LinkedList存储学生对象
		LinkedList stuLL = new LinkedList();
		stuLL.add(new Student("王林", 01));
		stuLL.add(new Student("陆沉", 03));
		stuLL.add(new Student("韩立", 02));
		// 使用sort方法，按姓名比较器进行排序
		Collections.sort(stuLL, new NameComparator());
		System.out.println("***按照学生姓名顺序输出学生信息***");
		Iterator it = stuLL.iterator();
		while (it.hasNext()) {
			System.out.println(it.next());
		}
		// 使用sort方法，按学号比较器进行排序
		Collections.sort(stuLL, new NumComparator());
		System.out.println("***按学生学号顺序输出学生信息***");
		it = stuLL.iterator();
		while (it.hasNext()) {
			System.out.println(it.next());
		}
	}
}
